function accur = knnclassifier(traindata, testdata, K)
for i = 1 : size(testdata)
    x = testdata(i,:);
    dist = sqrt((traindata(:, 1) - x(1)) .^ 2 + (traindata(:, 2) - x(2)) .^ 2 + (traindata(:, 3) - x(3)) .^ 2 + (traindata(:, 4) - x(4)) .^ 2);
    classes = traindata(:, 5);
    dist(:, 2) = classes;
    % 筛选出最近的k个
    poll = sortrows(dist, 1);
    % mode数组中出现次数最多的值
    expclass(i) = mode(poll(1 : K, 2));
end
%transpose向量的转置,nnz非零矩阵元素的数目
error = transpose(expclass) - testdata(:,5);
accur = ((size(error, 1) - nnz(error))/size(error, 1));
end
